package com.zhuiyun.pm.client.action.mapper;

import com.zhuiyun.pm.client.action.entity.GoodsEarnestMoneyEntity;
import com.zhuiyun.pm.client.action.entity.GoodsEntity;
import com.zhuiyun.pm.config.BaseMapper;
import com.zhuiyun.pm.config.CommonResult;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @ClassName GoodsEarnestMoneyMapper
 * @Description TODO 商品和用户保证金关联 mapper层
 * @Author 赵笛
 * @Date 2023/3/14 20:43
 **/

public interface GoodsEarnestMoneyMapper extends BaseMapper<GoodsEarnestMoneyEntity> {
    /**
     * @Author 赵笛
     * @Description TODO 根据当前登录用户id查询用户与商品的保证金信息
     * @Date 2023/3/14 20:42
     * @Return com.zhuiyun.pm.config.CommonResult
     * @param userId
     */
    @Select("select * from client_goods_earnest_money " +
            "where goods_id = #{goodsId} " +
            "and user_id = #{userId}")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "userId",column = "user_id"),
            @Result(property = "goodsId",column = "goods_id"),
            @Result(property = "startPrice",column = "start_price"),
            @Result(property = "earnestMoneyStatus",column = "earnest_money_status"),
            @Result(property = "endPrice",column = "end_price"),
            @Result(property = "transactionStatus",column = "transaction_status"),
            @Result(property = "createTime",column = "create_time"),
            @Result(property = "updateTime",column = "update_time"),
    })
    GoodsEarnestMoneyEntity getGoodsEarnestMoneyByUserId(@Param("userId") Integer userId,@Param("goodsId") Integer goodsId);

    @Select("select count(*) from client_goods_earnest_money where goods_id = #{goodsId}")
    Integer getGoodsEarnestMoneyCount(Integer goodsId);
    /**
     * @Author 赵笛
     * @Description TODO 修改保证金状态
     * @Date 2023/3/28 11:24
     * @Return com.zhuiyun.pm.config.CommonResult
     * @param goodsEarnestMoneyEntity
     */
    @Update("UPDATE client_goods_earnest_money " +
            "set earnest_money_status = 1 " +
            "where goods_id = #{goodsEarnestMoneyEntity.goodsId} " +
            "and user_id = #{goodsEarnestMoneyEntity.userId} ")
    int updateEarnestMoneyStatus(@Param("goodsEarnestMoneyEntity") GoodsEarnestMoneyEntity goodsEarnestMoneyEntity);
}
